<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>首页</title>
    <link rel="stylesheet" href="__PUBLIC__/jd/mui.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/jd/iconfont.css" />
    <link rel="stylesheet" href="__PUBLIC__/jd/app.css"/>
    <style>
        .notify{ display:block; height:23px; line-height:23px}
        .mui-table-view-cell:after{height: 0;background-color: transparent;}
        .cu-border-bottom{height: 1px;width:100%;content: '';-webkit-transform: scaleY(.5);transform: scaleY(.5);background-color: #c8c7cc;}
        .title-val{color: #e75349;text-align: center;font-size: 14px!important;}
        .title{text-align: center;}
        .shopping-body-titile div{color: #000;font-size: 18px;}
        .shopping-body-titile p span{font-size: 18px;color: #2b9aec;}
        .button{line-height: 1;background: #2b9aec;border: 1px solid #2b9aec;}
        .mui-badge{border-radius: 5px;color: #6dc7a4;background: #f3f6ff;}
        .mui-slider-indicator .mui-active.mui-indicator{background-color: #f15e70;}
    </style>

</head>
<body>
<div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="bottom: 50px;">
    <div class="mui-scroll">
        <div class="mui-content">
            <div id="slider" class="mui-slider">

            </div>
            <script id='carousel_template' type="text/template">
                <div class="mui-slider-group mui-slider-loop">
                    <%for(var i=0;i < carouselList.length;i++){%>
                    <div class="mui-slider-item mui-slider-item-duplicate">
                        <a _href="<%=carouselList[i]['url']%>" class="pageJumpA">
                            <img src="<%=carouselList[i]['pic_url']%>" alt="<%=carouselList[i]%>">
                        </a>
                    </div>
                    <%}%>
                </div>
                <div class="mui-slider-indicator">
                    <div class="mui-indicator mui-active"></div>
                    <%for(var i=0;i < carouselList.length-3;i++){%>
                    <div class="mui-indicator"></div>
                    <%}%>
                </div>
            </script>
            <div class="index-roll" style="display: none">
                <div id="index-rollBox">
                    <div class="iconfont icon-laba iconlaba iconcolor"></div>
                    <div id="index-rollText">

                    </div>
                    <script id='news_template' type="text/template">
                        <%for(var i=0;i < newsList.length;i++){%>
                        <a href="javascript:;" target="_parent" class="notify"><%=newsList[i]['createtime']%> <%=newsList[i]['msg_content']%> </a>
                        <%}%>
                    </script>
                </div>
            </div>
            <div class="mui-row index-row" id="cate">

            </div>
            <script id='cate_template' type="text/template">
                <%for(var i=0;i < cateList.length;i++){%>
                <div class="mui-col-xs-4 mui-col-sm-4">
                    <a href="javascript:;" data-id="<%=cateList[i]['id']%>" class="cate_list">
                        <div class="index-nav"><img src="<%=cateList[i]['pic_url']%>" alt=""/></div>
                    </a>
                    <div class="mui-media-body index-meta-title"><%=cateList[i]['cate_name']%></div>
                </div>
                <%}%>
            </script>
            <ul class="mui-table-view">
                <li class="mui-table-view-cell index-title">热门推荐</li>
            </ul>
            <ul class="mui-table-view" id="pro">

            </ul>
            <script id='pro_template' type="text/template">
                <%for(var i=0;i < proList.length;i++){%>
                <ul class="mui-table-view">
                    <li class="mui-table-view-cell mui-media">
                        <a href="javascript:;" class="pro_list">
                            <div class="shopping-img">
                                <img class="mui-media-object mui-pull-left" src="<%=proList[i]['pro_pic_url']%>">
                            </div>
                            <div class="mui-media-body">
                                <div class="shopping-body-titile">
                                    <div><%=proList[i]['pro_name']%></div>
                                    <p>已申请：<span><%=proList[i]['lenders_number']%></span></p>
                                </div>
                                <div class="shouping-money">
                                    <div>
                                        <p class="title-val"><%=proList[i]['loan_amount']%>元</p>
                                        <p class="title">可贷金额</p>
                                    </div>
                                    <div>
                                        <p class="title-val"><%=proList[i]['monthly_interest_rate']%>%</p>
                                        <p class="title">月利率</p>
                                    </div>
                                    <div>
                                        <p class="title-val"><%=proList[i]['lending_time']%></p>
                                        <p class="title">放款时间</p>
                                    </div>
                                </div>
                                <div class="shopping-msg">
                                    <p>
                                        <span class="mui-badge"><%=proList[i]['prompt_msg']%></span>
                                    </p>
                                </div>
                                <div class="shopping-msg">
                                    <p>&nbsp;</p>
                                    <p>
                                        <button type="button" class="mui-btn mui-btn-primary button submit" data-id="<%=proList[i]['id']%>" data-href="<%=proList[i]['pro_link']%>">立即申请</button>
                                    </p>
                                </div>
                            </div>
                        </a>
                    </li>
                </ul>
                <%}%>
            </script>
        </div>
    </div>
</div>
<nav class="mui-bar mui-bar-tab">
    <div class="tab-item mui-active">
        <div class="iconfont icon-zhuye"></div>
        <span class="mui-tab-label">主页</span>
    </div>
    <div class="tab-item" onclick="pageJump('/index/index/supermarket.html', true)" href="javascript:;" >
        <div class="iconfont icon-zhuyecanting"></div>
        <span class="mui-tab-label">产品超市</span>
    </div>
    <div class="tab-item" onclick="pageJump('/index/index/personal.html', false)" href="javascript:;" >
        <div class="iconfont icon-user"></div>
        <span class="mui-tab-label">个人中心</span>
    </div>
</nav>
<script src="__PUBLIC__/jd/jquery.min.js"></script>
<!-- 皮肤 start -->
<script>
    // 底部
    $('.mui-bar-tab').css('backgroundColor', "#f15e70");
    $('.mui-bar-tab .tab-item').css('color', "#ffffff");
    $('.mui-bar-tab .tab-item.mui-active').css('backgroundColor', "#ffffff");
    $('.mui-bar-tab .tab-item.mui-active').css('color', "#f15e70");
    //标题图标
    $('.iconlaba, .index-title').css('color', "#f15e70");
</script>
<!-- 皮肤 end -->
<script src="__PUBLIC__/jd/mui.min.js"></script>
<script src="__PUBLIC__/jd/rolltop.js"></script>
<script src="__PUBLIC__/jd/baiduTemplate.js"></script>
<script src="__PUBLIC__/jd/public.js"></script>
<script type="text/javascript">
    var page = 1, count = 0, isLoading = 1;
    //document.referrer;
    //轮播图数据处理
    function newCarouselData(data){
        var newData = data;
        newData.unshift(newData[newData.length - 1]);
        newData.push(newData[1]);
        return newData;
    }
    //mui初始化
    mui.init({
        pullRefresh: {
            container: '#pullrefresh',
            up: {
                contentrefresh: '正在加载...',
                callback: pullupRefresh
            }
        }
    });
    mui("#pullrefresh").on("tap",".cate_list",function(){
        var cate_id = this.getAttribute("data-id");
        window.location.href = '/index/index/supermarket?cate_id=' + cate_id;
    });

    mui("#pullrefresh").on("tap",".pageJumpA",function(){
        var isUser = localStorage.getItem("user");
        if(!isUser){
            mui.toast("您还没登录，请登录");
            setTimeout(function(){
                window.location.href = "/index/apply/login.html";
            }, 2000);
            return;
        } else {
            var href = this.getAttribute("_href");
            window.location.href = href;
        }
    });

    //mui点击
    mui("#pullrefresh").on("tap",".submit",function(){
        var href = this.getAttribute("data-href");
        var id = this.getAttribute("data-id");
        var isUser = localStorage.getItem("user");
        if(!isUser){
            mui.toast("您还没登录，请登录");
            setTimeout(function(){
                window.location.href = "/index/apply/login.html";
            }, 2000);
            return;
        } else {
            // $('.submit').attr("disabled",true);
            // $.post('/index/user/setApply', {"user_id": JSON.parse(isUser)["id"],"pro_id" : id},function(res){
            //     $('.submit').attr("disabled",false);
                // if(JSON.parse(res)["valid"] == 1){
                    window.location.href = href;
                // }
            // });
        }
    });


    //上拉加载具体业务实现
    function pullupRefresh() {
        setTimeout(function() {
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(page * 6 >= count);
            if(isLoading == 1){
                getProductData();
            }
        }, 600);
    }

    function getProductData(){
        $.get('/api/Jd/getProductData',{"page": page},function(data){
            var jsonp = data.data;
            // var jsonp = {
            //     "valid": 1,
            //     "dataList": [
            //         {
            //             "id": 153,
            //             "pro_name": "果冻小贷",
            //             "loan_amount": "1000-5000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.03,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535593874.jpg",
            //             "lenders_number": 21114,
            //             "prompt_msg": "76%通过",
            //             "pro_link": "http://www.zhaohuojr.com/xd/index.php?yqm=207355"
            //         },
            //         {
            //             "id": 149,
            //             "pro_name": "易借口贷",
            //             "loan_amount": "1000-3000",
            //             "lending_time": "24小时",
            //             "monthly_interest_rate": 0.01,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535427115.jpg",
            //             "lenders_number": 12983,
            //             "prompt_msg": "低于3000借款请不要申请",
            //             "pro_link": "https://yjkd.fanzhoutech.com/mobile/phoneverification?par=CD792F8ECD4052BC3E7B52345DB7E3FC"
            //         },
            //         {
            //             "id": 151,
            //             "pro_name": "钱宝宝",
            //             "loan_amount": "1000-3000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.02,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535528945.jpg",
            //             "lenders_number": 21872,
            //             "prompt_msg": "凭身份证就可下款",
            //             "pro_link": "https://loan-promotion.guangxzq.com/Qbb/s?r=AXFB"
            //         },
            //         {
            //             "id": 21,
            //             "pro_name": "花金宝",
            //             "loan_amount": "1000-10000",
            //             "lending_time": "15分钟",
            //             "monthly_interest_rate": 2,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535768407.jpg",
            //             "lenders_number": 12880,
            //             "prompt_msg": "秒下2k-5k",
            //             "pro_link": "https://huajinbao-agent.yylky.cn/mobile/gotodownload?518726F29D0AD92EDC50BD186B68FE461059930ED952B9D859E73CE2E0ADED62"
            //         },
            //         {
            //             "id": 148,
            //             "pro_name": "金龟子",
            //             "loan_amount": "1000-5000",
            //             "lending_time": "24小时",
            //             "monthly_interest_rate": 0.02,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535426932.jpg",
            //             "lenders_number": 21961,
            //             "prompt_msg": "极速审核，60秒下款。",
            //             "pro_link": "http://jinguizi.hnjjcy.com/Enjoy/template/reg.html?&t=001"
            //         },
            //         {
            //             "id": 150,
            //             "pro_name": "易速小贷",
            //             "loan_amount": "1000-10000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.03,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535427376.jpg",
            //             "lenders_number": 12337,
            //             "prompt_msg": "新产品，下款快。",
            //             "pro_link": "https://ysxd.fanzhoutech.com/mobile/phoneverification?par=9538855758D99C8EFF2FF877C66AD841"
            //         },
            //         {
            //             "id": 153,
            //             "pro_name": "果冻小贷",
            //             "loan_amount": "1000-5000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.03,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535593874.jpg",
            //             "lenders_number": 21114,
            //             "prompt_msg": "76%通过",
            //             "pro_link": "http://www.zhaohuojr.com/xd/index.php?yqm=207355"
            //         },
            //         {
            //             "id": 149,
            //             "pro_name": "易借口贷",
            //             "loan_amount": "1000-3000",
            //             "lending_time": "24小时",
            //             "monthly_interest_rate": 0.01,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535427115.jpg",
            //             "lenders_number": 12983,
            //             "prompt_msg": "低于3000借款请不要申请",
            //             "pro_link": "https://yjkd.fanzhoutech.com/mobile/phoneverification?par=CD792F8ECD4052BC3E7B52345DB7E3FC"
            //         },
            //         {
            //             "id": 151,
            //             "pro_name": "钱宝宝",
            //             "loan_amount": "1000-3000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.02,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535528945.jpg",
            //             "lenders_number": 21872,
            //             "prompt_msg": "凭身份证就可下款",
            //             "pro_link": "https://loan-promotion.guangxzq.com/Qbb/s?r=AXFB"
            //         },
            //         {
            //             "id": 21,
            //             "pro_name": "花金宝",
            //             "loan_amount": "1000-10000",
            //             "lending_time": "15分钟",
            //             "monthly_interest_rate": 2,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535768407.jpg",
            //             "lenders_number": 12880,
            //             "prompt_msg": "秒下2k-5k",
            //             "pro_link": "https://huajinbao-agent.yylky.cn/mobile/gotodownload?518726F29D0AD92EDC50BD186B68FE461059930ED952B9D859E73CE2E0ADED62"
            //         },
            //         {
            //             "id": 148,
            //             "pro_name": "金龟子",
            //             "loan_amount": "1000-5000",
            //             "lending_time": "24小时",
            //             "monthly_interest_rate": 0.02,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535426932.jpg",
            //             "lenders_number": 21961,
            //             "prompt_msg": "极速审核，60秒下款。",
            //             "pro_link": "http://jinguizi.hnjjcy.com/Enjoy/template/reg.html?&t=001"
            //         },
            //         {
            //             "id": 150,
            //             "pro_name": "易速小贷",
            //             "loan_amount": "1000-10000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.03,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535427376.jpg",
            //             "lenders_number": 12337,
            //             "prompt_msg": "新产品，下款快。",
            //             "pro_link": "https://ysxd.fanzhoutech.com/mobile/phoneverification?par=9538855758D99C8EFF2FF877C66AD841"
            //         },{
            //             "id": 150,
            //             "pro_name": "易速小贷",
            //             "loan_amount": "1000-10000",
            //             "lending_time": "2小时",
            //             "monthly_interest_rate": 0.03,
            //             "pro_pic_url": "http://wangdai.touch-game.cn/public/uploads/avatar/1535427376.jpg",
            //             "lenders_number": 12337,
            //             "prompt_msg": "新产品，下款快。",
            //             "pro_link": "https://ysxd.fanzhoutech.com/mobile/phoneverification?par=9538855758D99C8EFF2FF877C66AD841"
            //         }
            //     ],
            //     "count": 13
            // };
            count = jsonp["count"];
            if(jsonp["valid"]){
                if(count > 0){
                    var proData = {"proList": jsonp["dataList"]};
                }else {
                    var proData = {"proList": []};

                }
                var proHtml = baidu.template('pro_template', proData);
                $('#pro').append(proHtml);
                $('.title-val, .shopping-body-titile p span, .mui-badge').css('color', "#f15e70");
                $('.button').css({'color':"#ffffff",'backgroundColor': '#f15e70','border': '1px solid #f15e70'});
                page++;
                if(count <= 6){
                    isLoading = 0;
                }
            }
        });
    }

    //获取首页数据
    $.get('/api/Jd/Carousel',function(data) {
        // var json = JSON.parse(data);
        var json1 = data.data;
        // console.log(json1['carousel'].length)
        var json = {
            "carousel": [
                {
                    "pic_name": "banner-3",
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180831/bf11b49a8b65bd41777dfd4eb19a0bee.jpg",
                    "url": "https://ccshop.cib.com.cn:8010/application/cardapp/newfast/ApplyCard/toSelectCard?id=e3b7a37c2e724410a593c7f2735479a3"
                },
                {
                    "pic_name": "banner-2",
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180831/b81b4d2afe23ad14e2195d5127e8e18c.jpg",
                    "url": "http://xx.xmyidaitong.cn/admin/entry/entry.html?id=sq"
                },
                {
                    "pic_name": "banner-1",
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180831/1cd017720802a58504b6e94f4792d903.jpg",
                    "url": "http://xx.xmyidaitong.cn/admin/entry/entry.html?id=sq"
                }
            ],
            "news": [
                {
                    "msg_content": "138*****719用户在旺旺钱庄贷款成功",
                    "createtime": "05-16 17:52"
                },
                {
                    "msg_content": "159*****675用户在小小钱包贷款成功",
                    "createtime": "05-16 17:51"
                },
                {
                    "msg_content": "用户136****221在信合金融贷成功贷款",
                    "createtime": "05-02 10:54"
                },
                {
                    "msg_content": "用户178****337在你能贷成功贷款",
                    "createtime": "04-20 16:01"
                },
                {
                    "msg_content": "用户156****378在能森成功贷款",
                    "createtime": "04-20 15:52"
                },
                {
                    "msg_content": "用户139****271在天天放贷成功贷款",
                    "createtime": "05-16 17:49"
                }
            ],
            "cate": [
                {
                    "id": 1,
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180502/a25063f4131cd902c7e58b3402cf09fe.png",
                    "cate_name": "新品上线"
                },
                {
                    "id": 2,
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180502/3ab739c618dfde6d531ae1bd8bc06e23.png",
                    "cate_name": "高通过率"
                },
                {
                    "id": 3,
                    "pic_url": "http://wangdai.touch-game.cn/public/uploads/20180502/03ee83a5d0f428b036480bc28d46916b.png",
                    "cate_name": "大额产品"
                }
            ]
        };
        var newData;
        if(json1['carousel'].length > 1){
            newData = newCarouselData(json1['carousel']);
        } else {
            newData =  json1['carousel'];
        }
        var carData = {"carouselList": newData};
        var carHtml = baidu.template('carousel_template', carData);
        $('#slider').html(carHtml);


        var newsData = {"newsList": json['news']};
        var newsHtml = baidu.template('news_template', newsData);
        $('#index-rollText').html(newsHtml);


        var cateData = {"cateList": json['cate']};
        localStorage.setItem("cate_id", json['cate'][0]['id']);
        var cateHtml = baidu.template('cate_template', cateData);
        $('#cate').html(cateHtml);
        $('#index-rollText a, .index-meta-title').css('color', "#f15e70");
        //轮播图初始化
        var gallery = mui('.mui-slider');
        gallery.slider({
            interval: 3000
        });
        // $.get('/index/index/getTopData',function(data){
        //     var jsonp = JSON.parse(data);
        //     var jsonp = {
        //         "valid": 1,
        //         "dataList": [
        //
        //         ]
        //     };
        //     if(jsonp["valid"]){
        //         var proData = {"proList": jsonp["dataList"]};
        //         var proHtml = baidu.template('pro_template', proData);
        //         $('#pro').html(proHtml);
        //         $('.title-val, .shopping-body-titile p span, .mui-badge').css('color', "#f15e70");
        //         $('.button').css({'color':"#ffffff",'backgroundColor': '#f15e70','border': '1px solid #f15e70'});
        //     }
            getProductData();
        });

        //消息列表初始化
        textDiv = document.getElementById("index-rollText");
        textList = textDiv.getElementsByTagName("a");
        if(textList.length >= 2){
            textDat = textDiv.innerHTML;
            var br = textDat.toLowerCase().indexOf("<br",textDat.toLowerCase().indexOf("<br")+3);
            textDiv.innerHTML = textDat+textDat+textDat.substr(0,br);
            textDiv.style.cssText = "position:absolute; top:0;";
            textDatH = textDiv.offsetHeight;
            // MaxRoll();//注释消息滚动
        }
    // });
    function pageJump(url, cate_id){
        if(cate_id){
            window.location.href = url+'?cate_id=' + localStorage.getItem("cate_id");
        } else {
            window.location.href = url;
        }
    }
    if(GetQueryString('channel_id') !== null){
        sessionStorage.setItem('channelId',GetQueryString('channel_id'));
        var custom = sessionStorage.getItem("channelId");
        $.post('/admin/entry/addcount.html',{"custom": custom,"type": 1},function(res){});
    }
</script>
</body>
</html>